package com.zbf.设计模式1.原型模式;

import java.io.*;
import java.util.List;
import java.util.Map;

/**
 * @author: LI-CI-GAO
 * 作者: licigao
 * 日期: 2021/8/23  10:05
 * 描述:
 */
public class SourceTarget implements Cloneable,Serializable {

    public SourceTarget() {
        System.out.println("===构造====");
    }

    private List<Map<String,List<Map<String,Object>>>> list;

    private List<Map<String,List<Map<String,Object>>>> list2;

    private List<Map<String,List<Map<String,Object>>>> list3;


    public List<Map<String, List<Map<String, Object>>>> getList() {
        return list;
    }

    public void setList(List<Map<String, List<Map<String, Object>>>> list) {
        this.list = list;
    }

    /**
     * 作者: LI-CI-GAO
     * 日期: 2021/8/23  10:09
     * 描述: 浅克隆
     * @Param []
     * @Return com.zbf.设计模式1.原型模式.SourceTarget
     */
    public SourceTarget clone1() throws CloneNotSupportedException {

         return (SourceTarget)super.clone();
    }


    public void test01(){
        System.out.println("=========");
    }



    /**
     * 作者: LI-CI-GAO
     * 日期: 2021/8/23  10:22
     * 描述: 深克隆
     * @Param []
     * @Return com.zbf.设计模式1.原型模式.SourceTarget
     */
    public SourceTarget deepClone() throws IOException, ClassNotFoundException {


        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);

        objectOutputStream.writeObject(this);

        
        ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);

        Object object = objectInputStream.readObject();


        return (SourceTarget)object;
    }


}
